package com.ruoyi.web.controller.zhhq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhhq.domain.Usercate;
import com.ruoyi.zhhq.service.IUsercateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户分类Controller
 * 
 * @author ruoyi
 * @date 2022-10-20
 */
@RestController
@RequestMapping("/zhhq/usercate")
public class UsercateController extends BaseController
{
    @Autowired
    private IUsercateService usercateService;

    /**
     * 查询用户分类列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:usercate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Usercate usercate)
    {
        startPage();
        List<Usercate> list = usercateService.selectUsercateList(usercate);
        return getDataTable(list);
    }

    /**
     * 导出用户分类列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:usercate:export')")
    @Log(title = "用户分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Usercate usercate)
    {
        List<Usercate> list = usercateService.selectUsercateList(usercate);
        ExcelUtil<Usercate> util = new ExcelUtil<Usercate>(Usercate.class);
        util.exportExcel(response, list, "用户分类数据");
    }

    /**
     * 获取用户分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhq:usercate:query')")
    @GetMapping(value = "/{ucateId}")
    public AjaxResult getInfo(@PathVariable("ucateId") String ucateId)
    {
        return AjaxResult.success(usercateService.selectUsercateByUcateId(ucateId));
    }

    /**
     * 新增用户分类
     */
    @PreAuthorize("@ss.hasPermi('zhhq:usercate:add')")
    @Log(title = "用户分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Usercate usercate)
    {
        return toAjax(usercateService.insertUsercate(usercate));
    }

    /**
     * 修改用户分类
     */
    @PreAuthorize("@ss.hasPermi('zhhq:usercate:edit')")
    @Log(title = "用户分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Usercate usercate)
    {
        return toAjax(usercateService.updateUsercate(usercate));
    }

    /**
     * 删除用户分类
     */
    @PreAuthorize("@ss.hasPermi('zhhq:usercate:remove')")
    @Log(title = "用户分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ucateIds}")
    public AjaxResult remove(@PathVariable String[] ucateIds)
    {
        return toAjax(usercateService.deleteUsercateByUcateIds(ucateIds));
    }
}
